//
//  YDComposeTextView.swift
//  YDWeibo01
//
//  Created by suibian on 16/8/17.
//  Copyright © 2016年 iitcast. All rights reserved.
//

import UIKit

class YDComposeTextView: UITextView {
//    重写textView的font属性
    override var font:UIFont?{
        didSet{
        
        placehoderLabel.font = font
        
        }
    
    
    }
    var placehodel:String?{
        didSet{
        
        placehoderLabel.text = placehodel
        
        }
    
    
    }

    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

//    设置视图
    
    private func setUpUI(){
    
    backgroundColor = UIColor.whiteColor()
//        let txt = UITextField()
//       添加控件
        addSubview(placehoderLabel)
//        添加约束
        placehoderLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(8)
            make.leading.equalTo(5)
            make.width.equalTo(KSCREENW - 10)
        }
//        监听系统的通知 查看textView文字改变
        
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "textViewTextDidChange", name: UITextViewTextDidChangeNotification, object: nil)
    
    }
//    监听文字改变 让hoder的文字隐藏
    func textViewTextDidChange(){
    placehoderLabel.hidden = self.hasText()
    
    
    }
//    懒加载控件
    private lazy var placehoderLabel:UILabel = {
        let lab = UILabel()
        
        lab.textColor = UIColor.grayColor()

        lab.numberOfLines = 0

        return lab
    
    }()
}
